import React from "react";
class CastState extends React.Component {
  state = { islogin: true, books: ["dom编程艺术", "react进阶"] };
  handerClick = () => {
    let isflag = !this.state.islogin;
    this.setState({ islogin: isflag });
  };
  render() {
    return (
      <div>
        当前状态：{this.state.islogin.toString()} <hr />
        <br />
        {this.state.islogin === false ? (
          <p>您未登录</p>
        ) : (
          <div>
            <ul>
              {this.state.books.map((item) => (
                <li key={item}>{item}</li>
              ))}
            </ul>
          </div>
        )}
        <button onClick={this.handerClick}>切换islogin状态</button>
      </div>
    );
  }
}

export default CastState;
